# -*- coding: utf-8 -*-

from datetime import timedelta
from utils.operators.cluster_for_spark_sql_operator import SparkSqlOperator
from jms_hi.dwd.tab.dwd_tab_barscan_send_base_hi import jms_dwd__dwd_tab_barscan_send_base_hi
from jms_hi.dwd.oms.dwd_yl_oms_oms_order_hf import jms_dwd__dwd_yl_oms_oms_order_hf
from jms_hi.dim.dim_network_whole_massage import jms_dim__dim_network_whole_massage
from jms_hi.dim.dim_tms_mainline_vehicleloading import jms_dim__dim_tms_mainline_vehicleloading
from jms_hi.dim.dim_yl_tmsnew_tms_vehicle_line_base_dt import jms_dim__dim_yl_tmsnew_tms_vehicle_line_base_dt
from jms_hi.dim.dim_yl_tmsnew_tms_vehicle_point_base_dt import jms_dim__dim_yl_tmsnew_tms_vehicle_point_base_dt

jms_dm__dm_flow_direction_warning_dt = SparkSqlOperator(
    task_id='jms_dm__dm_flow_direction_warning_dt',
    email=['jarl.huang@jtexpress.com','yl_bigdata@yl-scm.com'],
    name='jms_dm__dm_flow_direction_warning_dt_{{ execution_date | cst_hour }}',
    sql='jms_hi/dm/dm_flow_direction_warning_dt/execute.sql',
    pool_slots=5,
    executor_cores=2,
    executor_memory='16G',
    driver_memory='4G',
    num_executors=16,  # spark.dynamicAllocation.enabled 为 True 时，num_executors 表示最少 Executor 数
    conf={'spark.dynamicAllocation.enabled': 'true',  # 动态资源开启
          'spark.shuffle.service.enabled': 'true',  # 动态资源 Shuffle 服务开启
          'spark.dynamicAllocation.maxExecutors': 20,  # 动态资源最大扩容 Executor 数
          'spark.dynamicAllocation.cachedExecutorIdleTimeout': 60,  # 动态资源自动释放闲置 Executor 的超时时间(s)
          'spark.executor.memoryOverhead': '2G',  # 堆外内存
          'spark.sql.autoBroadcastJoinThreshold': 104857600,  # MapJoin 阈值 100M
          'spark.sql.shuffle.partitions': 300,
          },
    hiveconf={
        'hive.exec.dynamic.partition': 'true',  # 动态分区
        'hive.exec.dynamic.partition.mode': 'nonstrict',
        'hive.exec.max.dynamic.partitions': 600,  # 每天生成 20 个分区
        'hive.exec.max.dynamic.partitions.pernode': 40,  # 每天生成 20 个分区
    },
    yarn_queue='pro',
    execution_timeout=timedelta(minutes=60),
)

jms_dm__dm_flow_direction_warning_dt << [
    jms_dwd__dwd_tab_barscan_send_base_hi,
    jms_dwd__dwd_yl_oms_oms_order_hf,
    jms_dim__dim_yl_tmsnew_tms_vehicle_line_base_dt,
    jms_dim__dim_yl_tmsnew_tms_vehicle_point_base_dt,
    jms_dim__dim_tms_mainline_vehicleloading,
    jms_dim__dim_network_whole_massage
]